<!DOCTYPE html>
<html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<label inert for="submit">Label for Submit</label>
<input id="text" type="text">
<input id="submit" type="submit">
<script>
function clickOn(element) {
    return new Promise(function(resolve, reject) {
        if (!window.eventSender)
            reject();

        var absoluteTop = 0;
        var absoluteLeft = 0;
        for (var parentNode = element; parentNode; parentNode = parentNode.offsetParent) {
            absoluteLeft += parentNode.offsetLeft;
            absoluteTop += parentNode.offsetTop;
        }

        var x = absoluteLeft + element.offsetWidth / 2;
        var y = absoluteTop + element.offsetHeight / 2;
        var pointerActions = [{
            source: "mouse",
            actions: [
                { name: "pointerMove", x: x, y: y },
                { name: "pointerDown", x: x, y: x },
                { name: "pointerUp" },
                { name: "pointerMove", x: 0, y: 0}
            ]
        }];
        chrome.gpuBenchmarking.pointerActionSequence(pointerActions, resolve);
    });
}

document.querySelector('#text').focus();

test(function() {
    label = document.querySelector('label');
    label.focus();
    assert_equals(document.activeElement, document.querySelector('#submit'));
}, 'Calling focus() on an inert label should still send focus to its target.');

promise_test(async () => {
    await clickOn(label);
    assert_equals(document.activeElement, document.body);
}, 'Clicking on an inert label should send focus to document.body.');
</script>
</html>
